/******************************************************************
Class: gas_phase_2nd_order
CREATED: Xinyu Zhang, 2009.05.01
******************************************************************/

#ifndef GAS_PHASE_2ND_ORDER_H
#define GAS_PHASE_2ND_ORDER_H

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#include "../../ThirdPartyCode/Numerical Recipes in CPP 2nd Ed/0_Matrix_and_Vector/nrtypes.h"
#include "../../ThirdPartyCode/Numerical Recipes in CPP 2nd Ed/2_LinearEquations/nr_LinearEquations.h"

const double X_IN_DEFAULT = 0.0;
const double X_S_DEFAULT = 0.0;

class gas_phase_2nd_order
{
	// Block Parameters
	double Kp;			// 2nd order model parameters
	double zeta;
	double tau;
	double P;			// Pressure, Pa
	double T;			// Temperature, K
	double Xs_ini;
	double t_begin;
	double t_end;
	double dt_int;		// Integration time	
	double dt_rec;		// Recording time, s
	// Internal variables
	double *t_arr;
	int	   t_idx;
	int    t_node;
	int	   Repeated;	
	double DepRate_max;
	char*  FileName;
	ofstream fout_detail;
	// States -----------------------
	double x[2];
	/*
	// For implicit method
	DP	   d;
	Vec_DP *x;
	Vec_DP b;
	Mat_DP A;
	Vec_INT indx;*/

	// Statistic data
	double *Xs_sum;
	double *Xs2_sum;
	double *DepRate_sum;
	double *DepRate2_sum;
	double *Xi_sum;
	double *Xi2_sum;

	
public:

	double time;		// Unit: s
	double Xs;			// Surface molar fraction
	double DepRate;		// Unit: Layer/s

	gas_phase_2nd_order(double iKp, double izeta, double itau,double iT, double iP, double it_end, double idt_int,double idt_ext,double iXs_ini = 0.0, char* iFileName = "gas_phase_2nd_order.dat");
	~gas_phase_2nd_order();
	double update_implicit(double Xin);
	double update_explicit(double Xin);
	int notfinish();
	void get();
	void reset();
};

#endif
